<template>
  <view class="styleUpload">
    <!-- <toast></toast> -->
    <!-- <u-navbar title="财务中心" :bgColor="navbarClass.titleBgColor" @leftClick="backHome" :placeholder="true"> </u-navbar> -->
    <view class="styleBg">
      <view class="uploaImg">
        <text class="txt1">风采图片</text>
        <u-upload :fileList="fileList" @afterRead="afterRead" @delete="deletePic" multiple :maxCount="1"></u-upload>
      </view>

      <view class="uploaImg">
        <text class="txt1">风采描述：</text>
        <u--textarea v-model.trim="content" count :height="160" maxlength="200" placeholder="请输入内容"></u--textarea>
      </view>

      <u-button style="margin: 24rpx 0" type="primary" text="提交" @click="uploadPicture"></u-button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      fileList: [],
      content: '',
    }
  },
  onLoad() {},
  methods: {
    // 上传风采照
    uploadPicture() {
      if (this.fileList.length == 0) {
        this.$u.toast('风采图片不能空')
        return
      }
      if (this.content == '') {
        this.$u.toast('风采描述不能空')
        return
      }
      this.$https
        .post({
          url: '/axh/insert/insertPictureAndDescribe',
          data: {
            image: this.fileList[0].url,
            content: this.content,
            phoneAuth: 1,
          },
        })
        .then((res) => {
          uni.showModal({
            title: '提示',
            content: '提交成功，等待审核！',
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                uni.redirectTo({
                  url: '/pageContent/introduction/styleDetails',
                })
              }
            },
          })
        })
    },
    async afterRead(e) {
      this.fileList = []
      uni.showLoading({
        title: '图片上传中',
      })
      const result = await this.uploadFilePromise(e.file[0].url)
      this.fileList.push({ url: result.result })
      uni.hideLoading()
    },
    // 删除图片
    deletePic(event) {
      this[`fileList${event.name}`].splice(event.index, 1)
    },

    gotoJump(url) {
      uni.navigateTo({
        url: url,
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.styleUpload {
  background: #f5f5f5;
  min-height: 100vh;
  .styleBg {
    background: #fff;
    padding: 24rpx;

    .uploaImg {
      .txt1 {
        display: block;
        color: #333333;
        font-size: 28rpx;
        padding-bottom: 18rpx;
      }
    }
  }
}
</style>
